<template>
  <!-- todo-list 列表中每一项 -->
  <div class="todo-item" :class="{ done: todoItem.completed }">
    <label>
      <input
        type="checkbox"
        :checked="todoItem.completed"
        @click="$emit('change-state', $event)"
      />
      {{ todoItem.content }}
      <span class="check-button"></span>
    </label>
  </div>
</template>

<script>
export default {
  name: "todo_list_item",
  props: ["todoItem"] // 父组件传入的每一项代办
}
</script>

<style scoped>
  /* todo-list 列表中每一项 */
  .todo-item {
    padding: 16px;
    border-radius: 8px;
    color: #626262;
    background: white;
  }

  .todo-item label {
    position: relative;
    display: flex;
    align-items: center;
  }

  .todo-item.done label {
    text-decoration: line-through;
    font-style: italic;
  }

  /* input 实现多选框功能，span 重写多选框样式 */
  .todo-item input {
    margin-right: 16px;
    opacity: 0;
  }

  .todo-item input:checked + span.check-button::after {
    opacity: 1;
  }

  /* 自定义复选框 span 元素的样式 */
  .todo-item label span.check-button {
    position: absolute;
    top: 0;
  }

  .todo-item label span.check-button::before,
  .todo-item label span.check-button::after {
    width: 18px;
    height: 18px;

    content: "";
    border-radius: 50%;

    display: block;
    position: absolute;
  }

  .todo-item label span.check-button::before {
    border: 1px solid #b382f9;
  }

  .todo-item label span.check-button::after {
    transition: 0.4s;
    background: #b382f9;
    transform: translate(1px, 1px) scale(0.8);
    opacity: 0;
  }
</style>